package com.atguigu;

import com.atguigu.util.JedisPoolUtil;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author 伟哥
 * @date 2021-06-21 11:15
 */
public class Jedis_04JedisPool {
    /**
     * 04、JedisPool线程池
     */
    @Test
    public void Test_04JedisPool() {
        JedisPool jedisPool = JedisPoolUtil.getJedisPoolInstance();
        JedisPool jedisPool2 = JedisPoolUtil.getJedisPoolInstance();
        // 测试单例模式
        System.out.println(jedisPool == jedisPool2);

        Jedis jedis = null;
        try {
            // 获取连接
            jedis = jedisPool.getResource();
            // 使用jedis
            jedis.set("aa", "bb");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 归还连接
            JedisPoolUtil.release(jedisPool, jedis);
        }
    }

}